//
//  KDCertificationViewController.m
//  LaiKeDaoClient
//
//  Created by dongkedi的iMac on 15/11/10.
//  Copyright © 2015年 LKD. All rights reserved.
//

#import "KDCertificationViewController.h"
#import "UIButton+WebCache.h"
@interface KDCertificationViewController ()
{
    UIScrollView    *_backScrollView;
    NSInteger       _currentTag;
}
@end

@implementation KDCertificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self setNaviLeftButton];
    [self setNaviTitle:@"医师资格认证"];
    
    _currentTag = 0;
    
    _backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kStatusBarHeight - kNavigationBarHeight)];
    _backScrollView.backgroundColor = [UIColor whiteColor];
    _backScrollView.contentSize = CGSizeMake(kScreenWidth,520);
    [self.view addSubview:_backScrollView];
    
    [self creareUI];
    
    _cameraView = [[KDCameraView alloc] init];
    _cameraView.cameraViewDelegate = self;

}

- (void)viewWillAppear:(BOOL)animated
{
    SharedAppDelegate.tabBarController.tabBarIsHiden = YES;
    [self requestGetDoctorAccred];
}

- (void)viewWillDisappear:(BOOL)animated
{
    SharedAppDelegate.tabBarController.tabBarIsHiden = NO;
}

//网络交互
//getDoctorAccred
- (void)requestGetDoctorAccred
{
    [CSHApiClient getDoctorAccredDidFinishLoaded:^(KXJson *json, NSString *path) {
        //
        if ([[json getStringForKey:@"code"] intValue] == 200) {
            NSDictionary *dic1 = [NSDictionary dictionaryWithDictionary:[json getObjectForKey:@"data"]];
            if (dic1[@"card_pic_path"]) {
                UIButton    *button1 = (UIButton *)[self.view viewWithTag:101];
                [button1 setImageWithURL:[NSURL URLWithString:dic1[@"card_pic_path"]] placeholderImage:[UIImage imageNamed:@"pic_ID-card.png"]];
            }
            if (dic1[@"work_pic_path"]) {
                UIButton    *button1 = (UIButton *)[self.view viewWithTag:102];
                [button1 setImageWithURL:[NSURL URLWithString:dic1[@"work_pic_path"]] placeholderImage:[UIImage imageNamed:@"pic_status.png"]];
            }
        }
    } didFailLoaded:^(NSError *error, NSString *path) {
        //
    }];
}

- (void)creareUI
{
    float   ButtonWidth = (kScreenWidth-60*2);
    float   ButtonHeight= 120;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:(CGRect){60,30,ButtonWidth,ButtonHeight}];
    [button setBackgroundColor:[UIColor clearColor]];
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    button.tag = 101;
    [button setImage:[UIImage imageNamed:@"pic_ID-card.png"] forState:UIControlStateNormal];
    [_backScrollView addSubview:button];
    
    UILabel     *label1= [[UILabel alloc] initWithFrame:(CGRect){0,Y(button)+ButtonHeight+14,kScreenWidth,14}];
    [label1 setTextAlignment:NSTextAlignmentCenter];
    [label1 setFont:[UIFont systemFontOfSize:14]];
    [label1 setBackgroundColor:[UIColor clearColor]];
    [label1 setText:@"点击上传身份证"];
    [label1 setTextColor:[UIColor colorWithHexString:@"666666"]];
    [_backScrollView addSubview:label1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button2 setFrame:(CGRect){60,Y(label1)+HEIGHT(label1)+30,ButtonWidth,ButtonHeight+20}];
    [button2 setBackgroundColor:[UIColor clearColor]];
    [button2 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    button2.tag = 102;
    [button2 setImage:[UIImage imageNamed:@"pic_status.png"] forState:UIControlStateNormal];
    [_backScrollView addSubview:button2];
    
    UILabel     *label2= [[UILabel alloc] initWithFrame:(CGRect){0,Y(button2)+ButtonHeight+20+14,kScreenWidth,14}];
    [label2 setTextAlignment:NSTextAlignmentCenter];
    [label2 setFont:[UIFont systemFontOfSize:14]];
    [label2 setBackgroundColor:[UIColor clearColor]];
    [label2 setTextColor:[UIColor colorWithHexString:@"666666"]];
    [label2 setText:@"点击上传医师资格证或工作证"];
    [_backScrollView addSubview:label2];
    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button3 setFrame:(CGRect){30,Y(label2)+HEIGHT(label2)+20,kScreenWidth-60,44}];
    [button3 setTitle:@"提交验证" forState:UIControlStateNormal];
    [button3.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button3 setBackgroundColor:kNavBlueColor];
    [button3 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    button3.tag = 103;
    [_backScrollView addSubview:button3];
}

- (void)buttonClick:(UIButton *)btn
{
    _currentTag = btn.tag;
    if (btn.tag == 101) {
        [_cameraView showCameraView:self];
    }else if (btn.tag == 102){
        [_cameraView showCameraView:self];
    }else if (btn.tag == 103){
        
    }
}

//delegate
- (void)chooseImage:(UIImage *)image
{
    UIButton    *button = (UIButton *)[self.view viewWithTag:_currentTag];
    
    [button setImage:image forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
